<template>
  <div class="upload-stock-box">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handMenuleSelect"
    >
      <el-menu-item index="1">更新库存时间</el-menu-item>
      <el-menu-item index="2">批量上传</el-menu-item>
      <el-menu-item index="3">批量粘贴</el-menu-item>
      <el-menu-item index="4">单条上传</el-menu-item>
    </el-menu>
    <div v-if="activeIndex === '4'" class="menu-box">
      <div class="upload-stock-menu menu-height">
        <el-form class="upload-form" :model="uploadForm" ref="uploadForm">
          <el-form-item>
            <el-row>
              <el-col :span="1"></el-col>
              <el-col :span="5"><span class="require">*</span>型号</el-col>
              <el-col :span="5"><span class="require">*</span>品牌</el-col>
              <el-col :span="3"><span class="require">*</span>数量</el-col>
              <el-col :span="2">封装</el-col>
              <el-col :span="2"><span class="require">*</span>批次</el-col>
              <el-col :span="3">包装</el-col>
              <el-col :span="2">最小起订量</el-col>
              <el-col :span="2">最小包装量</el-col>
              <el-col :span="3"><span class="require">*</span>币种</el-col>
              <el-col :span="3"><span class="require">*</span>库存所在地</el-col>
              <el-col :span="3">价格类型</el-col>
              <el-col :span="3"><span class="require">*</span>单价/最低阶梯价</el-col>
              <el-col :span="3">阶梯价格配置</el-col>
            </el-row>
          </el-form-item>
          <div
            class="dynami"
            v-for="(item, index) in uploadForm.inventoryList"
            :key="index"
          >
            <el-row>
              <el-col :span="1">
                <img
                  class="del-icon"
                  src="@/assets/images/del.png"
                  alt=""
                  @click="getDel(item, index)"
                  v-if="index !== 0"
                />
              </el-col>
              <el-col :span="5">
                <el-form-item
                  :prop="'inventoryList.' + index + '.partNumber'"
                  :rules="{
                    required: true,
                    message: '请填写型号',
                    trigger: 'blur',
                  }"
                >
                <el-tooltip class="item" effect="dark" :disabled="item.partNumber == ''?true:false" placement="top-start">
                  <div slot="content">{{ item.partNumber }}</div>
                  <el-autocomplete
                    type="text"
                    popper-class="myautocomplete"
                    :trigger-on-focus="isFocus"
                    v-model="item.partNumber"
                    :popper-append-to-body="false"
                    style="width: 90%"
                    value-key="partNumber"
                    :class="isRed[index] ? 'colorInput' : ''"
                    @select="handleSelect"
                    @change="partBlur(index, item)"
                    :fetch-suggestions="querySearch"  
                  
                  >
                  <template slot-scope="{ item }">

                    <span class="name">{{ item.partNumber }}</span>
                    <span class="addr">{{ item.brand }}</span>
                  </template>
                  </el-autocomplete>
                </el-tooltip>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item
                  :prop="'inventoryList.' + index + '.brand'"
                  :rules="{
                    required: isBrand,
                    message: '请填写品牌',
                    trigger: 'change',
                  }"
                >
                <el-tooltip class="item" effect="dark" :disabled="item.brand == ''?true:false" placement="top-start">
                  <div slot="content">{{ item.brand }}</div>
                  <el-input
                    type="text"
                    v-model="item.brand"
                    style="width: 90%"
                  />
                  </el-tooltip>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-form-item
                  :prop="'inventoryList.' + index + '.count'"
                  :rules="{
                    required: true,
                    message: '请填写库存数量',
                    trigger: 'blur',
                  }"
                >
                  <el-input
                    type="text"
                    @keyup.native="
                      item.count = item.count.replace(/[^\d]/g, '')
                    "
                    v-model="item.count"
                    style="width: 90%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="2">
                <el-input
                  type="text"
                  v-model="item.packages"
                  style="width: 90%"
                ></el-input>
              </el-col>
              <el-col :span="2">
                <el-form-item
                  :prop="'inventoryList.' + index + '.batch'"
                  :rules="{
                    required: true,
                    message: '请填写批次',
                    trigger: 'blur',
                  }"
                >
                  <el-input
                    type="text"
                    v-model="item.batch"
                    style="width: 90%"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-select
                  v-model="item.packing"
                  placeholder="请选择"
                  style="width: 90%"
                >
                  <el-option
                    v-for="val in packingOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="2">
                <el-input
                  type="text"
                  @keyup.native="item.moq = item.moq.replace(/[^\d]/g, '')"
                  v-model="item.moq"
                  style="width: 90%"
                  @blur="blurMoq(item.moq,index)"
                ></el-input>
              </el-col>
              <el-col :span="2">
                <el-input
                  type="text"
                  @keyup.native="item.mpq = item.mpq.replace(/[^\d]/g, '')"
                  v-model="item.mpq"
                  style="width: 90%"
                ></el-input>
              </el-col>
              <el-col :span="3">
                <el-select
                  v-model="item.currency"
                  placeholder="请选择"
                  style="width: 90%"
                  @change="changeCurreny(item.currency,index)"
                >
                  <el-option
                    v-for="val in currencyOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="3">
                <el-select
                  v-model="item.inventoryHome"
                  placeholder="请选择"
                  style="width: 90%"
                >
                  <el-option
                    v-for="val in placeOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="3">
                <el-select
                  v-model="item.unitPriceType"
                  placeholder="请选择"
                  style="width: 90%"
                >
                  <el-option
                    v-for="val in priceOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="3">
                <el-form-item
                  :prop="'inventoryList.' + index + '.unitPrice'"
                  :rules="{
                    required: true,
                    message: '请填写单价/最低阶梯价',
                    trigger: 'blur',
                  }"
                >
                <el-input
                  style="width: 90%"
                  v-model="item.unitPrice"
                  autocomplete="off"
                  @keyup.native="
                    item.unitPrice =
                      item.unitPrice.match(/^\d*(\.?\d{0,6})/g)[0] || null
                  "
                  @blur="priceBlur($event, index)"
                ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-select
                  v-model="item.ladderPriceId"
                  placeholder="请选择"
                  style="width: 90%"
                  v-if="item.unitPriceType == 2"
                  @change="selectPriceStep(item.ladderPriceId,item.moq,index)"
                >
                  <el-option
                    v-for="val in item.ladderPrice"
                    :key="val.id"
                    :label="val.name"
                    :value="val.id"
                  >
                    <el-popover placement="left" width="200" trigger="hover">
                      <el-table :data="val.ladderPriceConfigData" v-if="val.ladderPriceConfigData">
                        <el-table-column
                          property="mq"
                          align="center"
                          label="起订量"
                        ></el-table-column>
                        <el-table-column
                          v-if="val.ladderPriceConfigData[0].lower"
                          property="lower"
                          align="center"
                          label="降比"
                        ></el-table-column>
                        <el-table-column
                          v-if="val.ladderPriceConfigData[0].price"
                          property="price"
                          align="center"
                          label="阶梯价格"
                        ></el-table-column>
                      </el-table>
                      <el-button
                        slot="reference"
                        type="text"
                        style="width: 100%; color: black"
                      >
                        <span style="float: left">{{ val.name }}</span>
                      </el-button>
                    </el-popover>
                  </el-option>
                </el-select>
              </el-col>
            </el-row>
          </div>
        </el-form>
        <div class="add-btn">
          <img
            class="add-icon"
            src="@/assets/images/add.png"
            alt=""
            @click="getAddPrice"
          />
          <span>添加</span>
        </div>
      </div>
      <div class="upload-stock-footer">
        <el-button
          type="primary"
          @click="getaloneSubmit('uploadForm')"
          v-preventReClick
          :loading="loadingBtn"
        >
          <!-- 确认 -->
          <span v-if="!loadingBtn">去发布</span>
          <span v-else>发布中...</span>
        </el-button>
        <el-button @click="getConcel" class="resletBtn">取消</el-button>
      </div>
    </div>
    <div v-if="activeIndex === '2'">
      <div  class="upload-stock-menu menu-box">
        <div v-if="batchUpload.inventoryList.length == 0" v-loading="loading">
        <div class="upload-more">
          <span class="upload-files">上传文件：</span>
          <el-input class="input" v-model="file" />
          <el-upload
            ref="uploadXlsx"
            accept=""
            action
            :auto-upload="false"
            :on-change="importData"
            :show-file-list="false"
          >
            <el-button
              type="primary"
              v-if="batchUpload.inventoryList.length <= 0"
              >选择</el-button>
            <el-button type="primary" size="small" v-else>重新上传</el-button>
          </el-upload>
          <a href="./index.xlsx" class="loadbox" download="库存导入模板.xlsx"
            >下载库存模板</a
          >
        </div>
        <div class="export-way">
          <p>
            <el-button
              size="small"
              :class="exportActive == 1 ? 'export-btn' : ''"
              @click="exportBtn(1)"
              >添加方式上传</el-button
            >
            <span class="warning-tips">不更新网上相同的库存，但添加没有的库存</span>
          </p>
          <p>
            <el-button
              size="small"
              :class="exportActive == 2 ? 'export-btn' : ''"
              @click="exportBtn(2)"
              >覆盖方式上传</el-button
            >
            <span class="warning-tips">清除网上所有的库存信息</span>
          </p>
        </div>
        <div>
          <div class="tips">
            <div>提示：</div>
            <!-- <span
              >请按照以下模版格式整理您的库存，其中<u>型号</u>、<u>品牌</u>、<u>数量</u>、<u>批次</u>为必填。文件大小超过5M时，请将文件单独压缩成ZIP文件。</span
            > -->
            <p>
              1、请使用Excel模版，按照下图顺序整理您的库存，其中型号、品牌、数量、批次、币种和库存所在地为必填；
            </p>
            <p>
              2、Excel文件大小不得超过5M，若超过5M请将文件单独压缩成ZIP文件；
            </p>
            <p>
              3、当型号、品牌、数量、封装、批次、包装、MOQ、MPQ、币种、单价、库存所在地内容完全相同，此类库存默认为相同库存；
            </p>
          </div>
          <img class="table-pic" src="@/assets/images/upload.svg" alt="" />
        </div>
        </div>
        <div v-if="batchUpload.inventoryList.length > 0" class="table-width">
          <el-table
            ref="multipleTable"
            :data="batchUpload.inventoryList"
            tooltip-effect="dark"
            class="table-box"
            :height="tableHeight"
            @cell-click="getCell"
            :cell-class-name="getRowColumn"
            @selection-change="handleSelectionChange"
          >
          <el-table-column label="型号" width="120">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.partNumber"
                  @blur="inputBlur"
                  :class="scope.row.isParRed ? 'countInputColor' : ''"
                  @change="partChange(scope.row.index)"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="brand" label="品牌" width="120">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.brand"
                  @blur="inputBlur"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="count" label="数量">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.count"
                  @blur="inputBlur"
                  @input="(v) => (scope.row.count = v.replace(/[^\d]/g, ''))"
                >
                </el-input>
              </template>
            </el-table-column>
            <el-table-column prop="packages" label="封装" width="120">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.packages"
                  @blur="inputBlur"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="batch" label="批次" width="120">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.batch"         
                  @blur="inputBlur"
                  oninput="value=value.replace(/[^0-9+]/g,'')"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="packing" label="包装">
              <template slot-scope="scope">
                <el-select
                    v-model="scope.row.packing"
                  >
                    <el-option
                      v-for="val in packingOptions"
                      :key="val.value"
                      :label="val.label"
                      :value="parseInt(val.value)"
                    >
                    </el-option>
                  </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="moq" label="最小起订量">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.moq"
                  @blur="inputBlur"
                  oninput="value=value.replace(/[^0-9+]/g,'')"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="mpq" label="最小包装量">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.mpq"
                  @blur="inputBlur"
                  oninput="value=value.replace(/[^0-9]/g,'')"
                ></el-input>
              </template>
            </el-table-column>
          
            <el-table-column prop="currency" label="币种">
              <template slot-scope="scope">
                <el-select  v-model="scope.row.currency">
                  <el-option
                      v-for="val in currencyOptions"
                      :key="val.value"
                      :label="val.label"
                      :value="parseInt(val.value)"
                    >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="unitPrice" label="单价">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.unitPrice"
                  @blur="inputBlur"
                  @input="
                    scope.row.unitPrice =
                      scope.row.unitPrice.match(/^\d*(\.?\d{0,6})/g)[0] || null
                  "
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="inventoryHome" label="库存所在地">
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.inventoryHome"
                  >
                    <el-option
                      v-for="val in placeOptions"
                      :key="val.value"
                      :label="val.label"
                      :value="parseInt(val.value)"
                    >
                    </el-option>
                  </el-select>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
     
      <div class="upload-stock-footer" v-if="batchUpload.inventoryList.length > 0">
        <el-button
          type="primary"
          size="medium"
          @click="getUploadSubmit"
          :loading="loadingBtn"
        >
          <span v-if="!loadingBtn">去发布</span>
          <span v-else>发布中...</span>
        </el-button>
        <el-button size="medium" @click="getUploadConcel" class="resletBtn">取消</el-button>
      </div>
    </div>
    <div v-if="activeIndex === '3'" class="upload-activeBtn">
      <div
        class="left-upload"
        v-if="this.pasteUpload.inventoryList.length == 0"
      >
        <p class="operat">操作说明</p>
        <p class="left-tips">1、将要上传的库存在EXCEL表格里按照右侧示例填写</p>
        <p class="left-tips">
          2、从EXCEL表格中选中要上传的内容，复制粘贴到下面文本框内；
        </p>
        <p class="left-tips">3、单次最多批量粘贴5000个型号。</p>
        <img class="paste-pic" src="@/assets/images/paste.svg" alt="" />
        <div class="left-box">
          <el-input
            type="textarea"
            :rows="10"
            placeholder="内容粘贴处..."
            v-model="content"
          >
          </el-input>
        </div>
      </div>
      <div class="upload-stock-footer"  v-if="pasteUpload.inventoryList.length == 0">
        <el-button
          type="primary"
          size="small"
          @click="getconfirmSubmit(content)"
        >
          <span >确认</span>
        </el-button>
      <el-button size="small" @click="getPasteConcel" class="resletBtn">取消</el-button>
    </div>
      <div class="paste-table" v-if="pasteUpload.inventoryList.length > 0">
        <el-table
          ref="multipleTable"
          :data="pasteUpload.inventoryList"
          tooltip-effect="dark"
          :height="tableHeight"
          @cell-click="getpasteCell"
          :cell-class-name="getpasteRowColumn"
        >
          <el-table-column label="型号" width="120">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.partNumber"
                @blur="inputpasteBlur"
                @change="partPasteChange(scope.row.index)"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="brand" label="品牌" width="120">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.brand"
                @blur="inputpasteBlur"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="count" label="数量">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.count"
                @blur="inputpasteBlur"
                @input="(v) => (scope.row.count = v.replace(/[^\d]/g, ''))"
              >
              </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="packages" label="封装" width="120">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.packages"
                @blur="inputpasteBlur"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="batch" label="批次" width="120">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.batch"
                @blur="inputpasteBlur"
                oninput="value=value.replace(/[^0-9+]/g,'')"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="packing" label="包装">
            <template slot-scope="scope">
              <el-select
                  v-model="scope.row.packing"
                >
                  <el-option
                    v-for="val in packingOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="moq" label="最小起订量">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.moq"
                @blur="inputpasteBlur"
                oninput="value=value.replace(/[^0-9+]/g,'')"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="mpq" label="最小包装量">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.mpq"
                @blur="inputpasteBlur"
                oninput="value=value.replace(/[^0-9]/g,'')"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="unitPrice" label="单价">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.unitPrice"
                @blur="inputpasteBlur"
                @input="
                  scope.row.unitPrice =
                    scope.row.unitPrice.match(/^\d*(\.?\d{0,6})/g)[0] || null
                "
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="currency" label="币种">
            <template slot-scope="scope">
              <el-select  v-model="scope.row.currency">
                <el-option
                    v-for="val in currencyOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          
          <el-table-column prop="inventoryHome" label="库存所在地">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.inventoryHome"
                >
                  <el-option
                    v-for="val in placeOptions"
                    :key="val.value"
                    :label="val.label"
                    :value="parseInt(val.value)"
                  >
                  </el-option>
                </el-select>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="upload-stock-footer" v-if="pasteUpload.inventoryList.length > 0">
        <el-button
          type="primary"
          size="medium"
          @click="getPasteSubmit"
          :loading="loadingBtn"
        >
          <span v-if="!loadingBtn">去发布</span>
          <span v-else>发布中...</span>
        </el-button>
      <el-button size="medium" @click="getPasteConcel" class="resletBtn">取消</el-button>
    </div>
    </div>
    <div v-if="activeIndex === '1'" class="update-box">
      <el-button type="primary" size="medium" @click="updateDate">立即更新库存时间</el-button>
      <p>温馨提示：更新时间后库存日期会变为当前日期</p>
    </div>
    <!-- 删除 -->
    <el-dialog
      title="删除"
      :visible.sync="dialogDelVisible"
      width="20%"
      class="cancel-dialog"
    >
      <div class="del-box">
        <i class="el-icon-delete delete-icon"></i>
        <p class="del-content">您确认删除该库存数据吗？</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getDelSubmit()">确 认</el-button>
        <el-button @click="dialogDelVisible = false" class="resletBtn">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 发布提示 -->
    <el-dialog
      title="批量上传"
      :visible.sync="dialogPublishVisible"
      class="tips-dialog"
      width="30%"
    >
    <div class="handle-box">
      <img class="handle-pic" src="@/assets/images/handle.png" alt=""/>
      <p class="hanle-tit"  v-if="istipsType == 1">批量上传发布，已处理</p>
      <p class="hanle-tit" v-if="istipsType == 2">批量粘贴发布，已处理</p>
      <p class="hanle-tips"><span>{{ initTime}}</span>秒之后自动跳转到管理库存</p>
      <div>
        <el-button type="primary" size="small" @click="getpublish(istipsType)">继续发布产品</el-button>
        <el-button type="text" size="small" @click="getList">管理库存列表</el-button>
      </div>
    </div> 
    </el-dialog>
  </div>
</template>

<script>
import * as XLSX from "xlsx";
import JsZip from "jszip";
import iconv from "iconv-lite";
import {
  uploadFile,
  configFileReader,
  arrayBufferToBase64,
  dataURLtoFile,
} from "./index";
import {
  priceList,
  getLadderPriceData,
  addInventory,
  batchAddInventory,
  updateInventoryDate,
  deleteStandard,
  confirmStandard,
  queryBzkPartNumber,
} from "@/api/stock";
export default {
  name: "uploadStock",
  data() {
    return {
      activeIndex: "2", //el-menu
      model: "",
      active: 1,
      file: "",
      dataURL: "",
      exportActive: 0,
      pricebox: [[]],
      loading: false,
      uploadForm: {
        inventoryList: [
          {
            batch: "",
            brand: "",
            count: "",
            currency: 1,
            inventoryHome: 2,
            ladderPriceId: "",
            moq: "",
            mpq: "",
            packages: "",
            packing: "",
            partNumber: "",
            unitPrice: "",
            unitPriceType: 1,
          },
        ],
      },
      isBrand:true,
      placeOptions: [
        {
          value: "1",
          label: "中国大陆",
        },
        {
          value: "2",
          label: "中国香港",
        },
      ],
      currencyOptions: [
        {
          value: "1",
          label: "人民币",
        },
        {
          value: "2",
          label: "美元",
        },
      ],
      packingOptions: [
        {
          value: "1",
          label: "卷带(TR)",
        },
        {
          value: "2",
          label: "Pack",
        },
      ],
      priceOptions: [
        {
          value: "1",
          label: "单一价格",
        },
        {
          value: "2",
          label: "阶梯价格",
        },
      ],
      batchUpload: {
        importType: 1,
        inventoryList: [],
      },
      pasteUpload: {
        importType: 1,
        inventoryList: [],
      },
      ladderPricebox: [],
      pasteTable: [],
      isRed: [],
      isParRed: [],
      activeBtn: 1,
      isParShow: false,
      isBrandShow: false,
      isCountShow: false,
      isBatchShow: false,
      isPriceShow: false,
      multipleSelection: [],
      tabColumnIndex: 0,
      tabRowIndex: 0,
      isCount: false,
      reg: "",
      batchReg: "",
      priceReg: "",
      currencyReg: "",
      content: "",
      dataArr: [],
      isWordshow: false,
      isrightWordshow: false,
      zipList: [], //压缩包解析前文件列表
      flagLength: "", //用于记录异步解读的条数
      upFlagSum: 0, //用于计数当前解读的文件为第几条
      resultList: [],
      tabpasteRowIndex: 0,
      pastetabColumnIndex: 0,
      tableconfig: {
        loading: false,
        isselection: true,
        ispagination: true,
        isfixed: true,
        tabledata: [],
        isindex: true,
        thead: [
          { sort: null, label: "型号", prop: "partNumber", width: 200 },
          {
            sort: null,
            label: "标准匹配型号",
            prop: "standardPar",
            width: 200,
            type: "slot",
          },
          { sort: null, label: "品牌", prop: "brand", width: 200 },
          {
            sort: null,
            label: "标准匹配品牌",
            prop: "standardBrand",
            width: 200,
            type: "slot",
          },
          { sort: null, label: "数量", prop: "count", width: 100 },
          { sort: null, label: "批次", prop: "batch", width: 120 },
          { sort: null, label: "封装", prop: "packages" },
          {
            sort: null,
            label: "价格类型",
            prop: "unitPriceType",
            width: 120,
            type: "slot",
          },
          {
            sort: null,
            label: "单价",
            prop: "unitPrice",
            width: 120,
            type: "slot",
          },
          {
            sort: null,
            label: "币种",
            prop: "currency",
            width: 100,
            type: "slot",
          },
        ],
        checkedPage: false, //全选本页
        isError: false,
        currentpage: 1,
        pagesize: 1,
        total: 3,
      },
      theadList: [],
      selectrow: [],
      form: {
        pageNo: 1,
        pageSize: 10,
      },
      dialogDelVisible: false,
      dialogPublishVisible:false,//发布提示
      isdisabled: true,
      brandId: [],
      confirmArr: [{}],
      isError: [],
      selectPartNamber: [[]],
      loadingBtn: false,
      dialogTipsVisible: false,
      counBox: {
        successCount: 0,
        allCount: 0,
        failCount: 0,
      },
      tableHeight: window.innerHeight - 270,
      restaurants: [
        {
          id: 1,
          name: "AD300",
        },
        {
          id: 2,
          name: "AD301",
        },
        {
          id: 3,
          name: "AD302",
        },
        {
          id: 4,
          name: "AD304",
        },
      ],
      initTime: 5,//倒计时5秒
      timeName:null,
      istipsType:0,//发布类型
      isClick:0,//是否点击事件
      isFocus:false,//是否上传单条的弹框
      resultItem:'',//单条上传选中值
      resultindex:0,
      uploadResult:[],
    };
  },
  methods: {
    handMenuleSelect(key, keyPath) {
      console.log(key, keyPath);
      this.activeIndex = key;
    },
    leftTime() {
      this.initTime--;
      console.log(this.initTime);
      if(this.initTime == 0){
        this.$router.push('/manageStock');
        clearInterval(this.timeName)
      }
      if(this.isClick != 0){
        this.initTime =5;
        clearInterval(this.timeName)
      }
    },
    getList(){
      this.isClick = 1;
      this.$router.push('/manageStock');
    },
    getpublish(type){
      this.isClick = 1;
      if(type==1){
        this.activeIndex='2'
        this.file = "";
        this.batchUpload.importType = 1;
        this.batchUpload.inventoryList = [];
        this.dialogPublishVisible=false;
      }else{
        this.activeIndex='3';
        this.pasteUpload.inventoryList = [];
        this.content = "";
        this.dataArr = [];
        this.dialogPublishVisible=false;
      }
    },
    // 更新日期
    updateDate(){
      let params={
        isAll:true
      }
      updateInventoryDate(params).then(res=>{
        if(res.success){
          this.$message.success(res.message);
        }else{
          this.$message.error(res.message);
        }
      })
    },
    exportBtn(val) {
      this.exportActive = val;
      this.batchUpload.inventoryList = this.uploadResult;
      this.batchUpload.inventoryList.map(item=>{
          if(item.packing == '卷带(TR)'){
            item.packing = 1;
          }else if(item.packing == 'Pack'){
            item.packing = 2;
          }else{
            item.packing = '';
          }
          if(item.inventoryHome == '中国大陆'){
            item.inventoryHome = 1;
          }else if(item.inventoryHome == '中国香港'){
            item.inventoryHome = 2;
          }else{
            item.inventoryHome = '';
          }
          if(item.currency == '人民币'){
            item.currency = 1;
          }else if(item.currency == '美元'){
            item.currency = 2;
          }else{
            item.currency = '';
          }
        })

    },
    getPriceList() {
      priceList().then((res) => {
        if (res.success) {
          // console.log(res, "阶梯价格");
          this.ladderPricebox = res.result.data;
          this.uploadForm.inventoryList.map((item) => {
            this.$set(item, "ladderPrice", this.ladderPricebox);
          });
        }
      });
    },
    blurMoq(val,index){
      // console.log(val,index,this.uploadForm.inventoryList[index].ladderPriceId,'333333');
      if(this.uploadForm.inventoryList[index].ladderPriceId != ''){
        this.uploadForm.inventoryList[index].ladderPrice.map(item=>{
          if(item.id == this.uploadForm.inventoryList[index].ladderPriceId){
            if(val != '' && val != null){
              if(Number(val)< Number(item.ladderPriceConfigData[0].mq)){
                this.uploadForm.inventoryList[index].moq="";
                this.$message.warning('阶梯价格起订量大于库存起订量，请修改库存起订量或重新选择阶梯价格');
                return false;
              }
            }
           
          }
        })
      }
    },
    selectPriceStep(val,moq,index){
      console.log(val,moq,'valvalval');
      this.uploadForm.inventoryList[index].ladderPrice.map(item=>{
      if(item.id == val){
        if(moq != '' &&  moq != null){
          if(Number(moq)< Number(item.ladderPriceConfigData[0].mq)){
            this.uploadForm.inventoryList[index].ladderPriceId="";
            this.$message.warning('阶梯价格起订量大于库存起订量，请修改库存起订量或重新选择阶梯价格');
            return false;
          }
        }
      }
     })

    },
    changeCurreny(val,index){
      let params = {
        currency:val ,
        unitPrice:this.uploadForm.inventoryList[index].unitPrice,
      };
      if(params.unitPrice != ''){
        getLadderPriceData(params).then((res) => {
        if (res.success) {
          this.uploadForm.inventoryList[index].ladderPrice = res.result;
          // console.log(res, "jiekk");
        }
      });
      }
     
    },
    priceBlur(e, index) {
      console.log(e, index, "3333333333");
      if (e.target.value != "") {
        if (e.target.value == 0) {
          this.uploadForm.inventoryList[index].ladderPrice = this.ladderPricebox;
        } else {
          let params = {
            currency: this.uploadForm.inventoryList[index].currency,
            unitPrice: e.target.value,
          };
          getLadderPriceData(params).then((res) => {
            if (res.success) {
              this.uploadForm.inventoryList[index].ladderPrice = res.result;
              console.log(res, "jiekk");
            }
          });
        }
      }
    },
    getAddPrice() {
      this.uploadForm.inventoryList.push({
        batch: "",
        brand: "",
        count: "",
        currency: 1,
        inventoryHome: 2,
        ladderPriceId: "",
        ladderPrice: this.ladderPricebox,
        moq: "",
        mpq: "",
        packages: "",
        packing: "",
        partNumber: "",
        unitPrice: "",
        unitPriceType: 1,
      });
    },
    getDel(item, index) {
      this.uploadForm.inventoryList.splice(index, 1);
    },
    partChange(index) {
      this.$set(this.batchUpload.inventoryList[index], "isParRed", false);
    },
    partPasteChange(index) {
      this.$set(this.pasteUpload.inventoryList[index], "isPasteRed", false);
    },
    getaloneSubmit(formName) {
      this.isBrand = true;
      this.$forceUpdate();
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loadingBtn = true;
          addInventory(this.uploadForm).then((res) => {
            console.log(res, "res单条上传");
            if (res.success) {
              this.loadingBtn = false;
              this.$message.success("提交成功");
              this.uploadForm.inventoryList.map((item, index) => {
                item.batch = "";
                item.brand = "";
                item.count = "";
                item.currency = 1;
                item.inventoryHome = 2;
                item.ladderPriceId = "";
                (item.ladderPrice = this.ladderPricebox), (item.moq = "");
                item.mpq = "";
                item.packages = "";
                item.packing = "";
                item.partNumber = "";
                item.unitPrice = "";
                item.unitPriceType = 1;
                this.pricebox[index] = [];
              });
              this.uploadForm.inventoryList = this.uploadForm.inventoryList.splice(0, 1);
              this.isBrand = false;
            } else {
              this.loadingBtn = false;
              if(res.code == 400){
                this.isBrand = true;
              }else{
                this.$message.error(res.message);
              }
              
            }
          });
        } else {
          return false;
        }
      });
    },
    handleSelect(item) {
      if (item) {
        this.uploadForm.inventoryList[this.resultindex].partNumber =item.partNumber;
        this.uploadForm.inventoryList[this.resultindex].brand =item.brand;
        this.uploadForm.inventoryList[this.resultindex].moq =item.moq;
        this.uploadForm.inventoryList[this.resultindex].mpq =item.mpq;
        this.uploadForm.inventoryList[this.resultindex].packages =item.packages;
        this.uploadForm.inventoryList[this.resultindex].packing =item.packing;
      }
    },
    partBlur(index, item) {
      this.$forceUpdate();
      this.isRed[index] = false;
      this.resultindex = index;
      // console.log(this.resultindex,'this.resultindex');
    },
    querySearch(queryString, cb) {
      console.log(queryString, "queryStringqueryString");
      if(queryString != ''){
        // this.isFocus = true;
        let params = {
          partNumber:queryString
        }
        queryBzkPartNumber(params).then(res=>{
          // console.log(res,'paramsparams');
          this.restaurants = res.result
          let results =  this.restaurants;
          // var results = queryString ? this.restaurants.filter(this.createFilter(queryString)) : this.restaurants;
          cb(results);
        })
      }else{
        // this.isFocus = false;
      }
    },
    getConcel() {
      this.uploadForm.inventoryList.map((item) => {
        item.batch = "";
        item.brand = "";
        item.count = "";
        item.currency = 1;
        item.inventoryHome = 2;
        item.ladderPriceId = "";
        (item.ladderPrice = this.ladderPricebox), (item.moq = "");
        item.mpq = "";
        item.packages = "";
        item.packing = "";
        item.partNumber = "";
        item.unitPrice = "";
        item.unitPriceType = 1;
      });
    },
    importData(file, fileList) {
      this.loading = true;
      this.batchUpload.inventoryList = [];
      this.isWordshow = false;
      // console.log(file, fileList, "file wen");
      let testFile = file.name
        .substring(file.name.lastIndexOf(".") + 1)
        .toLowerCase();
      const extension = testFile === "xlsx" || testFile === "xls";
      const zipextension =
        testFile === "xlsx" || testFile === "xls" || testFile === "zip";
      let imgSize = Number(file.size / 1024 / 1024);
      if (!zipextension) {
        this.loading = false;
        this.$message({
          message: "上传文件只能是xls/xlsx和zip文件！",
          type: "warning",
          offset: window.screen.height / 3,
        });
        return false;
      } else {
        if (extension) {
          if (imgSize > 5) {
            this.$message({
              message: "文件大小超过5M，请上传ZIP文件！",
              type: "warning",
              offset: window.screen.height / 3,
            });
            this.loading = false;
            return false;
          } else {
            this.handleNumBatch(file);
          }
        } else {
          this.zipXlsxUpload(file);
        }
      }
      this.file = file.name;
    },
    handleNumBatch(file) {
      const f = file.raw;
      // 用 FileReader 来读取
      let reader = new FileReader();
      // 重写 FileReader 上的 readAsBinaryString 方法
      FileReader.prototype.readAsBinaryString = (f) => {
        let binary = "";
        let wb; // 读取完成的数据
        let outdata; // 你需要的数据
        let reader = new FileReader();
        reader.onload = (e) => {
          // 读取成Uint8Array，再转换为Unicode编码（Unicode占两个字节）
          let bytes = new Uint8Array(reader.result);
          let length = bytes.byteLength;
          for (let i = 0; i < length; i++) {
            binary += String.fromCharCode(bytes[i]);
          }
          // 接下来就是xlsx了，具体可看api
          wb = XLSX.read(binary, {
            type: "binary",
            cellDates: false,
          });
          outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
          console.log(outdata, "outdataoutdataoutdataoutdata");
          const result = this.generateParam(outdata);
          console.log("result--", result);
          this.loading = false;
          this.uploadResult = result;
        };
        reader.readAsArrayBuffer(f);
      };
      reader.readAsBinaryString(f);
    },
    //3.上传ZIP压缩包，读取并处理其中XLSX数据相关方法--
    zipXlsxUpload(file) {
      var zip = new JsZip();
      //解压zip
      zip
        .loadAsync(file.raw, {
          //解决文件名乱码问题
          decodeFileName: function (bytes) {
            return iconv.decode(bytes, "gbk");
          },
        })
        .then((file) => {
          //excel文件列表
          this.zipList = file.files;
          //摘除非excel数据
          let arr = [];
          for (let key in this.zipList) {
            if (/\.(xlsx)$/.test(key)) {
              arr.push(this.zipList[key]);
            }
          }
          const asyncReaderList = arr.filter(
            (r) => !r.dir && r.name.indexOf("MACOSX") === -1
          );
          //因为id只存在于文件名，所以解析前进行需要的数据拼接
          let asyncReaderListCopy = [];
          asyncReaderList.forEach((item) => {
            let obj = {
              // 员工Id格式：文件夹名/12345678姓名.xlsx
              value: zip.file(item.name).async("uint8array"),
              name: item.name,
            };
            asyncReaderListCopy.push(obj);
          });
          console.log(asyncReaderListCopy, "asyncReaderListCopy");
          //用于reader.onload异步调用计数
          this.flagLength = asyncReaderListCopy.length;
          asyncReaderListCopy.forEach((zipFile) => {
            //用于取到promise中的数据
            Promise.resolve(zipFile.value).then((item) => {
              //1>用于附件上传，预览功能
              let base = arrayBufferToBase64(item);
              // Base64 转 File 对象
              const result = dataURLtoFile(base, zipFile.name);
              console.log(result, "最终解压后的File对象");
              this.resultList.push(result);
              //2>用于读取每个excel页签里的内容
              const reader = new FileReader(zipFile.name);
              console.log(reader, "reader.onload");
              reader.onload = (e) => {
                this.onReaderLoad(e);
              };
              reader.readAsBinaryString(new Blob([item]));
            });
          });
        })
        .catch((err) => {
          // 请求失败
          this.$message({
            message: err,
            type: "error",
            offset: window.screen.height / 3,
          });
        });
    },
    //4取出XLSX文件数据
    onReaderLoad(e) {
      this.batchUpload.inventoryList = [];
      let excelData = e.target.result;
      //  //设置时间读取格式1>.{ type: "binary" ,cellDates:true,cellText:false}
      const workbook = XLSX.read(excelData, {
        type: "binary",
        cellDates: true,
        cellText: false,
      });
      console.log(workbook, "workbookworkbookworkbook");
      if (workbook.Sheets) {
        const worksheet = workbook.Sheets[workbook.SheetNames[0]];
        //设置时间读取格式2>.{ raw: false,dateNF: 'yyyy/mm/dd'}
        const data = XLSX.utils.sheet_to_json(worksheet);
        console.log(data);
        const result = this.generateParam(data);
        this.loading = false;
        this.batchUpload.inventoryList = result;
        this.batchUpload.inventoryList.map(item=>{
            if(item.packing == '卷带(TR)'){
              item.packing = 1;
            }else if(item.packing == 'Pack'){
              item.packing = 2;
            }else{
              item.packing = '';
            }
            if(item.inventoryHome == '中国大陆'){
              item.inventoryHome = 1;
            }else if(item.inventoryHome == '中国香港'){
              item.inventoryHome = 2;
            }else{
              item.inventoryHome = '';
            }
            if(item.currency == '人民币'){
              item.currency = 1;
            }else if(item.currency == '美元'){
              item.currency = 2;
            }else{
              item.currency = '';
            }
          })

      }
    },
    // 生成导入参数
    generateParam(data) {
      const params = [];
      // 这里根据实际表格 title 值、接口参数值，灵活变化
      const parse = {
        "品牌*": "brand",
        "型号*": "partNumber",
        "批次*": "batch",
        "数量*": "count",
        '币种*': "currency",
        "库存所在地*": "inventoryHome",
        MOQ: "moq",
        MPQ: "mpq",
        封装: "packages",
        包装: "packing",
        '单价*': "unitPrice",
      };
      data.forEach((item) => {
        let obj = {};
        const keys = Object.keys(parse);
        const itemKeys = Object.keys(item);
        itemKeys.forEach((key) => {
          const val = item[key];
          if (keys.includes(key)) {
            obj[parse[key]] = val;
          }
        });
        params.push(obj);
      });
      return params;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getCell(row, column, cell, event) {
      this.tabRowIndex = row.index;
      this.tabColumnIndex = column.index;
    },
    getRowColumn({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex;
      column.index = columnIndex;
    },
    getpasteCell(row, column, cell, event) {
      this.tabpasteRowIndex = row.index;
      this.pastetabColumnIndex = column.index;
    },
    getpasteRowColumn({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex;
      column.index = columnIndex;
    },
    inputpasteBlur() {
      this.tabpasteRowIndex = null;
      this.pastetabColumnIndex = "";
    },
    inputBlur() {
      this.tabRowIndex = null;
      this.tabColumnIndex = "";
    },
    getUploadSubmit() {
      this.loadingBtn = true;
      this.batchUpload.importType = this.exportActive;
      if (this.batchUpload.inventoryList.length > 0) {
        batchAddInventory(this.batchUpload).then((res) => {
          if (res.success) {
            this.loadingBtn = false;
            this.isClick = 0;
            this.istipsType = 1;
            this.dialogPublishVisible= true;
            this.timeName=setInterval(this.leftTime, 1000)
            this.batchUpload.inventoryList = [];
            this.exportActive = 0;
            this.uploadResult = [];
          } else {
            this.loadingBtn = false;
            this.$message.error(res.message)
          }
        });
      } else {
        this.$message.warning('请上传数据');
        this.loadingBtn = false;
      }
    },
    getUploadConcel() {
      this.file = "";
      this.batchUpload.importType = 0;
      this.exportActive = 0;
      this.batchUpload.inventoryList = [];
      this.uploadResult = [];
    },
    getconfirmSubmit(e){
      this.handleNumber(e);
    },
    handleNumber(source) {
      let rows = source.split("\n"); // 拆成很多行
      let dataObj = {
        partNumber: "",
        brand: "",
        count: "",
        packages: "",
        batch: "",
        packing: "",
        moq: "",
        mpq: "",
        currency: "",
        unitPrice: "",
        inventoryHome: "",
      };
      this.dataArr = [];
      for (let i = 0; i < rows.length; i++) {
        if (rows[i] != "") {
          // 如果某一行不是空，再按列拆分
          let columns = rows[i].split("\t"); // 已经按列划分
          // console.log(columns, "columnscolumns");
          this.pasteUpload.inventoryList[i] = dataObj;
          let keys = Object.keys(this.pasteUpload.inventoryList[i]);
          let dataone = {};
          for (let j = 0; j < columns.length; j++) {
            dataone[keys[j]] = columns[j].replace(/[\r\n]/g, "");
          }
          this.dataArr.push(dataone);
        }
      }
      this.pasteUpload.inventoryList = this.dataArr;
      this.pasteUpload.inventoryList.map((item, index) => {
        if(item.brand=='品牌*'){
          this.pasteUpload.inventoryList.splice(index,1);
        }
      });
      this.pasteUpload.inventoryList.map(item => {
        if(item.packing == '卷带(TR)'){
          item.packing = 1;
        }else if(item.packing == 'Pack'){
          item.packing = 2;
        }else{
          item.packing = '';
        }
        if(item.inventoryHome == '中国大陆'){
          item.inventoryHome = 1;
        }else if(item.inventoryHome == '中国香港'){
          item.inventoryHome = 2;
        }else{
          item.inventoryHome = '';
        }
        if(item.currency == '人民币'){
          item.currency = 1;
        }else if(item.currency == '美元'){
          item.currency = 2;
        }else{
          item.currency = '';
        }
      })
      // console.log(this.pasteUpload.inventoryList,'this.pasteUpload.inventoryList');
    },
    getPasteSubmit() {
      this.loadingBtn = true;
      if (
        this.pasteUpload.inventoryList.length <= 5000 &&
        this.pasteUpload.inventoryList.length > 0
      ) {
        // let arr = [];
        // this.pasteUpload.inventoryList.map(item=>{
        //   if(item.brand=='' || item.partNumber=='' || item.count=='' || item.batch=='' || item.currency ==''|| item.inventoryHome==''){
        //     arr.push(item)
        //   }
        // })
        // if(arr.length>0){
        //   // console.log(arr,'aeeeeee');
        //   this.loadingBtn = false;
        //   this.$message.warning("库存模板的必填项未填,请输入");
        //   return false;
        // }
        batchAddInventory(this.pasteUpload).then((res) => {
          if (res.success) {
            this.loadingBtn = false;
            this.isClick = 0;
            this.istipsType = 2;
            this.dialogPublishVisible= true;
            this.timeName=setInterval(this.leftTime, 1000)
          } else {
            this.loadingBtn = false;
            this.$message.error(res.message);
            // if (res.code == 100) {
            //   this.$message({
            //     message: res.message,
            //     type: "error",
            //     offset: window.screen.height / 3,
            //   });
            //   let result = res.result.data;
            //   this.pasteUpload.inventoryList.map((item, index) => {
            //     // this.$set(this.pasteUpload.inventoryList[index],'isParRed',false);
            //     result.map((val) => {
            //       if (item.partNumber == val) {
            //         item.isPasteRed = true;
            //       }
            //     });
            //   });
            //   // console.log(this.pasteUpload.inventoryList,'shhssssssssssssssss');
            // } else if (res.code == 400) {
            //   this.$message({
            //     message: res.message,
            //     type: "error",
            //     offset: window.screen.height / 3,
            //   });
            // }
          }
        });
      } else {
        this.loadingBtn = false;
        this.$message({
          message: "单次最多批量粘贴5000个型号",
          type: "warning",
          offset: window.screen.height / 3,
        });
        // this.$message.warning('单次最多批量粘贴5000个型号');
      }
    },
    getPasteConcel() {
      this.pasteUpload.inventoryList = [];
      this.content = "";
      this.dataArr = [];
    },
    handleSelectChange(section) {
      this.selectrow = section;
      if (this.selectrow.length >= 1) {
        this.isdisabled = false;
      } else {
        this.isdisabled = true;
      }
      console.log(this.selectrow, "333333");
    },
    // 页码数更新
    handleSizeChange(val) {
      this.form.pageNo = 1;
      this.form.pageSize = val;
      this.doQuery();
      //表格回到顶部
      this.$refs.mytable.$emit("handleGoTop");
    },
    // 当前页码更新
    handleCurrentChange(val) {
      this.form.pageNo = val;
      console.log(this.form.pageNo, "this.tableconfig.currentpage");
      this.doQuery();
      //表格回到顶部
      this.$refs.mytable.$emit("handleGoTop");
    },
    async doQuery() {
      this.tableconfig.loading = true;
      this.tableconfig.currentpage = this.form.pageNo;
      this.tableconfig.pagesize = this.form.pageSize;
      // let data1 = await queryUnMatchData(this.form);
      // console.log(data1, "列表");
      // if (data1.success) {
      //   this.tableconfig.total = data1.result.count;
      //   this.tableconfig.tabledata = data1.result.data;
      //   this.tableconfig.tabledata.map((item) => {
      //     this.$set(item, "standardPar", "");
      //     this.$set(item, "standardBrand", "");
      //     if (typeof item.bzkPartNumber == "string") {
      //       item.standardPar = item.bzkPartNumber;
      //       item.standardBrand = item.bzkBrand;
      //     } else {
      //       if (
      //         item.bzkPartNumber != null &&
      //         item.bzkPartNumber != undefined &&
      //         item.bzkPartNumber.length == 1
      //       ) {
      //         item.standardPar = item.bzkPartNumber[0].partNumber;
      //       }
      //       if (
      //         item.bzkBrand != null &&
      //         item.bzkBrand != undefined &&
      //         item.bzkBrand.length == 1
      //       ) {
      //         item.standardBrand = item.bzkBrand[0].brand;
      //       }
      //     }
      //   });
      //   console.log(this.tableconfig.tabledata, "列333333333333333表");
      //   this.handleArry(this.tableconfig.tabledata);
      // }
      this.tableconfig.loading = false;
    },
    changeStandardPar(data, val, key) {
      this.tableconfig.tabledata.map((item) => {
        if (item.id == data.id) {
          item.bzkPartNumber.map((par) => {
            if (par.partNumber == val) {
              item.standardBrand = par.brand;
            }
          });
        }
      });
      this.handleArry(this.tableconfig.tabledata);
    },
    changeStandardBrand(data, val, key) {
      this.tableconfig.tabledata.map((item) => {
        if (item.id == data.id) {
          item.bzkBrand.map((par) => {
            if (par.brand == val) {
              item.standardPar = par.partNumber;
            }
          });
        }
      });
      this.handleArry(this.tableconfig.tabledata);
    },
    handleArry(tableDa) {
      let arr = [];
      for (var i = 0; i < tableDa.length; i++) {
        for (var j = i + 1; j < tableDa.length; j++) {
          if (
            tableDa[i].standardBrand == tableDa[j].standardBrand &&
            tableDa[i].standardPar == tableDa[j].standardPar &&
            tableDa[i].standardBrand != "" &&
            tableDa[j].standardBrand != "" &&
            tableDa[i].standardPar != "" &&
            tableDa[j].standardPar != ""
          ) {
            arr.push(tableDa[i]);
            arr.push(tableDa[j]);
          }
        }
      }
      console.log(arr, "arr.push(this.tableconfig.tabledata[i]);");
      let arrBox = [...new Set(arr)];
      console.log(arrBox, "arrBoxarrBoxarrBox");
      // this.handleArry(arrBox);
      tableDa.map((item, index) => {
        this.isError[index] = false;
        this.tableconfig.isError = false;
      });
      // console.log(arr,'arrarrarrarrarrarrarrarr');
      if (arrBox.length >= 2) {
        tableDa.map((item, index) => {
          arrBox.forEach((obj) => {
            if (item == obj) {
              console.log(index, "3333333333333");
              this.isError[index] = true;
              this.tableconfig.isError = true;
              return false;
            }
          });
        });
      }
    },
    getSumbit() {
      this.handleArry(this.tableconfig.tabledata);
      let conArr = [];
      this.selectrow.map((item) => {
        if (item.standardPar == "" || item.standardBrand == "") {
          conArr.push(item);
        }
      });
      console.log(conArr, "djjjjjjjjj");
      if (conArr.length > 0) {
        this.$message({
          message: "请选择标准匹配型号和标准匹配品牌",
          type: "warning",
          offset: window.screen.height / 3,
        });
        return false;
      }
      this.selectrow.map((item, index) => {
        this.confirmArr[index] = {};
        this.$set(this.confirmArr[index], "id", item.id);
        this.$set(this.confirmArr[index], "bzkBrand", item.standardBrand);
        this.$set(this.confirmArr[index], "bzkPartNumber", item.standardPar);
      });
      let params = {
        dataList: this.confirmArr,
      };
      confirmStandard(params).then((res) => {
        // console.log(res,'this.confirmArrthis.confirmArr');
        if (res.success) {
          this.$message.success(res.message);
          this.doQuery();
          this.confirmArr = [];
        } else {
          console.log(res.result, "result");
          this.$message({
            message: res.message,
            type: "error",
            offset: window.screen.height / 3,
          });
        }
      });
    },
    getDelete() {
      let arr = [];
      this.selectrow.map((val) => {
        arr.push(val.id);
      });
      this.dialogDelVisible = true;
      this.brandId = arr;
    },
    getDelSubmit() {
      let params = {
        idList: this.brandId,
      };
      deleteStandard(params).then((res) => {
        if (res.success) {
          this.$message({
            message: res.message,
            type: "success",
            offset: window.screen.height / 3,
          });
          this.dialogDelVisible = false;
          this.brandId = [];
          this.doQuery();
          this.tableconfig.tabledata.map((item, index) => {
            this.isError[index] = false;
            this.tableconfig.isError = false;
          });
        }
      });
    },
  },
  created() {
    this.reg = /[^0-9]/;
    this.batchReg = /[^0-9+]/;
    this.priceReg = /^[0-9]{1}\d{0,9}(\.\d{1,6})?$/;
    this.currencyReg = !("人民币" || "美元");
    this.getPriceList();
    this.theadList = this.tableconfig.thead;
    this.doQuery();
    // this.handleArry(arr);
  },
  watch: {
    isBrand:{
      handler(val,old){
        console.log(val,'rrrrrrrrr');
      },
      immediate:true,
      deep:true,
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-popper[x-placement^=bottom] {
  width: auto !important;
}
.upload-stock-box {
  width: 100%;
  padding: 20px 0;
  ::v-deep .el-menu--horizontal > .el-menu-item.is-active{
    border-bottom: 2px solid #2348E8;
    font-size: 14px;
    font-weight: 600;
    color: #1A2035;
    // line-height: 20px;
  }
  ::v-deep .el-menu--horizontal > .el-menu-item{
    height: 40px !important;
    line-height: 40px !important;
    font-size: 14px;
    font-weight: 600;
    color: #1A2035;
    padding: 0;
    margin-right: 30px;
  }
  .upload-stock-header {
    margin: 10px 24px 10px;
    .activeColor {
      color: #fff;
      // background-color: #1682e6;
      // border-color: #1682e6;
    }
    .activeColor:active {
      color: #fff;
      // background-color: #1682e6;
      // border-color: #1682e6;
    }
    .activeColor:focus {
      color: #fff;
      // background-color: #1682e6;
      // border-color: #1682e6;
    }
    .excel-btn {
      color: #fff;
      // background-color: #44d7b6;
      // border-color: #44d7b6;
    }
    .excel-box:hover {
      // color: #44d7b6;
      // background-color: #fff;
      // border-color: #44d7b6;
    }
    .excel-btn:active {
      color: #fff;
      // background-color: #44d7b6;
      // border-color: #44d7b6;
    }
    .excel-btn:hover {
      color: #fff;
      // background-color: #44d7b6;
      // border-color: #44d7b6;
    }
  }

  .del-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    .delete-icon {
      font-size: 50px;
      color: #008fff;
    }
    .del-content {
      font-size: 24px;
      font-weight: 600;
      color: #333333;
      line-height: 22px;
    }
    img {
      width: 60px;
      height: 60px;
      display: block;
    }
  }
  .menu-box{
    height: 100%;
  }
  .menu-height{
    height: 85%;
    overflow-y: auto;
  }
  .menu-box{
    border-bottom:none !important;
  }
  .upload-stock-menu {
    margin: 24px 0 0;
    height: calc(100vh - 260px);
    border-bottom: 1px solid #EEEEEE;
    overflow-y: auto;
   
    .upload-form {
      .el-row {
        display: flex;
        // margin-bottom: 20px;
       
        .brand-error {
          padding-left: 8%;
        }
        .count-error {
          padding-left: 15%;
        }
        .batch-error {
          padding-left: 30%;
        }
        .price-error {
          padding-left: 82.5%;
        }
      }
      .dynami{
        .el-row {
          margin-bottom: 20px;
        }
      }
      .require {
        color: #e02020;
      }
      .el-form-item {
        // margin-right: 5px;
        // display: flex;
        .line {
          text-align: right;
        }
      }
    }
    .add-btn {
      margin:0 0 0 .77%;
      display: flex;
      font-size: 14px;
      align-items: center;
      .add-icon {
        width: 16px;
        height: 16px;
        display: block;
        margin-right: .77%;
      }
    }
    .del-icon {
      width: 16px;
      height: 16px;
      margin: 10px auto 0;
      display: block;
    
    }
    .upload-more {
      display: flex;
      .upload-files{
        font-size: 14px;
        font-weight: 400;
        color: #1A2035;
        line-height: 22px;
      }
      .input {
        width: 320px;
        margin: 0 5px;
      }
    }
    .upload-add {
      margin-left: 70px;
      margin-top: 10px;
      .activeColor {
        color: #fff;
        background-color: #1682e6;
        border-color: #1682e6;
      }
    }
    .tips {
      width: 100%;
      margin: 30px 0;
      font-size: 12px;
      font-weight: 400;
      color: #333333;
      line-height: 24px;
      u {
        color: red;
        text-decoration: none;
      }
      p {
        line-height: 20px;
        margin: 5px 0;
      }
    }
    .table-pic {
      width: 661px;
      display: block;
    }
    .paste-pic{
      width: 46%;
      display: block;
      margin-top: 10px;
    }
    .table-width{
      // height: 90%;
      // width: 99%;
    }
    .loadbox {
      margin: 0 10px 0;
      display: block;
      font-size: 12px;
      font-weight: 400;
      color: #2348E8;
      line-height: 30px;
      cursor: pointer;
    }
    .export-way {
      margin: 10px 0 0 5%;
      .export-btn {
        color: #fff;
        background-color: #2348E8;
        border-color: #2348E8;
      }
      // span {
      //   font-size: 14px;
      //   margin-left: 10px;
      //   display: inline-block;
      //   // color: #eeeeee54;
      // }
      .warning-tips{
        font-size: 12px;
        font-weight: 400;
        color: #999999;
        line-height: 22px;
        margin-left: 10px;
        
      }
    }
  }
 ::v-deep .el-button:hover, .el-button:focus {
    color: #fff;
    border-color: #2348E8;
    background-color: #2348E8;
}
  .colorInput {
    .el-input__inner {
      border-color: #ff4949 !important;
      color: #ff4949 !important ;
    }
  }
  .unmatched-btn {
    padding: 10px 0 20px 48px;
  }
  .unmatched-table {
    background: #ffffff;
    padding: 20px;
    margin: 0 20px;
    // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
    .unmatchedtable-box {
      width: 100%;
      .el-table {
        margin-bottom: 20px;
      }
      .is-error {
        .el-input__inner {
          border-color: #f56c6c;
        }
      }
      .type-box {
        text-align: center;
      }
      .type-look {
        text-align: center;
        color: #008fff;
        cursor: pointer;
      }
      .system-pagination {
        right: 40px;
      }
    }
    .error {
      font-size: 14px;
      font-weight: 400;
      color: #e02020;
      line-height: 20px;
    }
  }
  ::v-deep .el-table .cell{
      padding: 10px !important;
    }
  .table-box {
    width: 100%;
  
    // margin: 20px 0 20px;
    .countColor {
      color: #e02020;
    }
    .countInputColor {
      .el-input__inner {
        color: #e02020 !important;
      }
    }
  }
  .paste-table {
    width: 100%;
    height: calc(100vh - 260px);
    border-bottom: 1px solid #EEEEEE;
    // margin-bottom: 20px;
    .countColor {
      color: #e02020;
    }
    .countInputColor {
      .el-input__inner {
        color: #e02020 !important;
      }
    }
  }

  .upload-activeBtn {
    margin: 0 0;
    padding: 24px 0 0;
    // display: flex;
    .el-card__body {
      display: flex;
      width: 100%;
    }
    .left-upload {
      width: 100%;
      height: calc(100vh - 260px);
      border-bottom: 1px solid #EEEEEE;
      .operat {
        font-size: 14px;
        font-weight: 600;
        color: #000000;
        line-height: 20px;
        margin-bottom: 10px;
      }
      .left-tips {
        margin: 5px 0;
        font-size: 12px;
        font-weight: 400;
        line-height: 20px;
      }
      P {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        line-height: 32px;
        margin: 0;
      }
      // .table-img{
      //   width: 50%;
      // }
      .left-box {
        margin: 10px 0 20px;
        width: 90%;
      }
    }
    .right-upload {
      width: 55%;
      .right {
        // width: 40%;
        height: 144px;
        display: block;
      }
      .right-error {
        margin: 10px 0 0;
      }
    }
  }
 
  .update-box{
    margin-top: 24px;
    p{
      width: 40%;
      font-size: 12px;
      font-weight: 400;
      color: #C68300;
      line-height: 32px;
      background: #FFF6DB;
      padding: 0 0 0 10px;
      margin: 15px 0;
    }
  }
  .form-item__error {
    color: #e02020;
    font-size: 14px;
  }
  .upload-stock-footer {
    // margin-left: 24px;
    // margin-top: 20px;
    text-align: center;
    margin-top: 20px;
  }
  .result-tips {
    width: 100%;
    font-size: 14px;
    font-weight: 400;
    color: #000000;
    line-height: 22px;
    text-align: center;
    p {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .total-num {
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      line-height: 22px;
      margin-bottom: 10px;
      text-align: center;
    }
    img {
      width: 16px;
      height: 16px;
      display: block;
      margin-left: 10px;
    }
    .btn {
      width: 50%;
      margin-top: 10px;
      background: #2348e8;
      border-radius: 4px;
      color: #ffffff;
    }
  }
}
.cancel-dialog {
  .el-dialog:not(.is-fullscreen) {
    margin-top: 30vh !important;
    .el-dialog__header {
      display: none;
    }
  }
  .dialog-footer {
    text-align: center;
  }
}
.tips-dialog {
  .el-dialog:not(.is-fullscreen) {
    margin-top: 30vh !important;
    .el-dialog__header{
      margin: 20px;
      // padding: 0;
      border-bottom: 1px solid #DDDDDD;;
    }
    .el-dialog__body {
      padding: 0px 10px 30px;
    }
  }
}
.tips-dialog{
  text-align: center;
  .handle-pic{
  width: 72px;
  height: 72px;
  display: block;
  margin: auto;
}
.hanle-tit{
  font-size: 24px;
  font-weight: 600;
  color: #333333;
  line-height: 33px;
  margin: 10px 0 20px;
}
.hanle-tips{
  font-size: 14px;
  font-weight: 400;
  color: #333333 ;
  line-height: 20px;
  margin: 0 0 30px;
  span{
    color: #008FFF;
  }
  }
}
.myautocomplete{
  width: 230px !important;
  .name{
   color: #333333;
  }
  .addr{
    font-size: 12px;
    color: #b4b4b4;
    margin-left: 20px;
  }

}

</style>